home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / dax1.exe / DAP / DAPE / DAPSTAT.C < prev    next >
Text File  |  1992-07-15  |  5KB  |  147 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      dapstat.c                                             ║
  4. //   ║ abstract:    This module contains the support for printing some    ║
  5. //   ║              stats on the server screen.  If the constant          ║
  6. //   ║              DAPSTATISTICS is FALSE, this module contains nothing. ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Network C for NLMs SDK                                ║
  10. //   ║              CLib v3.11                                            ║
  11. //   ║                                                                    ║
  12. //   ║  This software is provided as is and carries no warranty           ║
  13. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  14. //   ║  warranties of merchantability, title and fitness for a particular ║
  15. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  16. //   ║  your requirements or that the software is without defect or error ║
  17. //   ║  or that operation of the software will be uninterrupted.  You are ║
  18. //   ║  using the software at your risk.  The software is not a product   ║
  19. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  20. //   ║                                                                    ║
  21. //   ╟────────────────────────────────────────────────────────────────────╢
  22. //   ║ maintenance history:                                               ║
  23. //   ║ level    date      pi   description                                ║
  24. //   ╟────────────────────────────────────────────────────────────────────╢
  25. //   ║  001   03/03/92    kl   initial release.                           ║
  26. //   ╚════════════════════════════════════════════════════════════════════╝
  27.  
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <process.h>
  31. #include <errno.h>
  32. #include <library.h>
  33. #include "dap/dapsys.h"
  34.  
  35. #if DAPSTATISTICS
  36.  
  37. STATIC  LONG        statThreadID;
  38. //
  39. // number of clients w/allocated session
  40. //
  41. DAPSTAT DAPActiveSessions = {0,1,1,0,"Active Sessions"};
  42.  
  43. //
  44. // total number of requests processed
  45. //
  46.  
  47. DAPSTAT DAPTotalRequests = {0,1,2,0," Total Requests"};
  48.  
  49. //
  50. // total number of login requests
  51. //
  52.  
  53. DAPSTAT DAPLoginRequests = {0,1,1,29,"Logins"};
  54.  
  55. //
  56. // total number of requests processed
  57. //
  58.  
  59. DAPSTAT DAPLogoutRequests = {0,1,2,28,"Logouts"};
  60.  
  61. //
  62. // highest number of transactions per second
  63. //
  64.  
  65. DAPSTAT DAPTPSPeak = {0,1,1,50,"Peak Transactions/Sec"};
  66.  
  67. //
  68. // current number of transactions per second
  69. //
  70.  
  71. DAPSTAT DAPTPSCurrent = {0,1,2,47,"Current Transactions/Sec"};
  72.  
  73. //
  74. //  This is the thread which prints statistics on the server screen.
  75. //  It uses lines 1 thru 4 on the screen.
  76. //
  77.  
  78. STATIC  void    DAPUpdateScreenStats(void *threadID)
  79. {
  80.         LONG    lastTotal = 0;
  81.         #define SuspendOrStop() if(!*(LONG *)threadID){ExitThread(EXIT_THREAD,0);}
  82.         #define UpdateScreen(x) if(x.updated){x.updated = FALSE; DAPatprintf(x.row,x.col,"%s: %-5d",x.desc,x.value);}
  83.  
  84.         *(LONG *)threadID = GetThreadID();
  85.  
  86.         while( 1 ){
  87.             //
  88.             //  Delay 1 second waiting for changes
  89.             //
  90.             delay(1000);
  91.             SuspendOrStop();
  92.             //
  93.             //  Figure the peak and current TPS
  94.             //
  95.             if( DAPTotalRequests.updated ){
  96.                 DAPTPSCurrent.value = DAPTotalRequests.value - lastTotal;
  97.                 lastTotal = DAPTotalRequests.value;
  98.                 DAPTPSCurrent.updated |= 1;
  99.                 if( DAPTPSCurrent.value > DAPTPSPeak.value ){
  100.                     DAPTPSPeak.value = DAPTPSCurrent.value;
  101.                     DAPTPSPeak.updated |= 1;
  102.                 }
  103.             }
  104.             else{
  105.                 DAPTPSCurrent.value = 0;
  106.                 DAPTPSCurrent.updated |= 1;
  107.             }
  108.             //
  109.             //  Now update the needed figures on the screen
  110.             //
  111.             UpdateScreen(DAPActiveSessions);
  112.             UpdateScreen(DAPTotalRequests);
  113.             UpdateScreen(DAPLoginRequests);
  114.             UpdateScreen(DAPLogoutRequests);
  115.             UpdateScreen(DAPTPSPeak);
  116.             UpdateScreen(DAPTPSCurrent);
  117.             SuspendOrStop();
  118.         }
  119. }
  120.  
  121. T_RC    DAPInitializeStatLogic()
  122. {
  123.         char    *divider = "────────────────────────────────────────────────────────────────────────────────";
  124.  
  125.         if( BeginThread(DAPUpdateScreenStats,NULL,8192,&statThreadID) == EFAILURE ){
  126.             DIAG4("Could not start UpdateScreenStats thread");
  127.             return DAP_RESOURCE_ERROR;
  128.         }
  129.         DAPatprintf(0,0,divider);
  130.         DAPatprintf(0,28,"┤ DAP Engine Statistics ├");
  131.         DAPatprintf(3,0,divider);
  132.         DAPatprintf(23,0,divider);
  133.         ThreadSwitch();         // let the thread run once...
  134.         DIAG4("DAP Stat Logic has been initialized");
  135.         return DAP_SUCCESS;
  136. }
  137.  
  138. void    DAPDeInitializeStatLogic()
  139. {
  140.         if( statThreadID ){
  141.             statThreadID = 0;       // signal thread to shut down ...
  142.         }
  143.         DIAG4("DAP Stat Logic has been DE-initialized");
  144. }
  145.  
  146. #endif
  147.